using System;
using System.Data;
using ATTools.Models;
using Orchard.ContentManagement.MetaData;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;
using Orchard.Environment.Extensions;

namespace ATTools
{
    [OrchardFeature("ATTools")]
    public class Migrations : DataMigrationImpl
    {
        public int Create()
        {
            SchemaBuilder.CreateTable("SoundRecord", table => table
                .ContentPartRecord()
                .Column("SoundString", DbType.String)
                .Column("UseCustomSound", DbType.Boolean)
                .Column("CustomSoundString", DbType.String)
                .Column("LanguageOfSound", DbType.String)
            );
            
            ContentDefinitionManager.AlterPartDefinition(
                typeof(SoundPart).Name, cfg => cfg.Attachable());

                
            SchemaBuilder.CreateTable("ATToolsSettingsPartRecord", table => table
                .ContentPartRecord()
                .Column("VoiceName", DbType.String)
                .Column("BingAppID", DbType.String)
               );


            SchemaBuilder.CreateTable("TextsizeRecord", table => table
                .ContentPartRecord()
            );

            ContentDefinitionManager.AlterPartDefinition(
                typeof(TextsizePart).Name, cfg => cfg.Attachable());
                
            return 1;
        }

    }

    [OrchardFeature("ATTools.MicrosoftTranslatorWidget")]
    public class MigrationsTranslatorWidget : DataMigrationImpl
    {
        public int Create()
        {

            SchemaBuilder.CreateTable("TranslationWidgetRecord", table => table
                .ContentPartRecord()
                .Column("Color", DbType.String)
                .Column("BorderColor", DbType.String)
                .Column("Width", DbType.String)
            );

            ContentDefinitionManager.AlterTypeDefinition("TranslationWidget", cfg => cfg
                .WithPart("TranslationWidgetPart")
                .WithPart("WidgetPart")
                .WithPart("CommonPart")
                .WithSetting("Stereotype", "Widget")
            );

            return 1;
        }
    }

    [OrchardFeature("ATTools.VoiceCommands")]
    public class MigrationsVoiceCommands : DataMigrationImpl
    {
        public int Create()
        {
            SchemaBuilder.CreateTable("VoiceCommandRecord", table => table
                .Column("Id", DbType.Int32, column => { column.PrimaryKey(); column.Identity(); })
                .Column("Description", DbType.String)
                .Column("CommandType", DbType.Byte)
                .Column("CommandData", DbType.String)
            );

            SchemaBuilder.CreateTable("VoiceCommandsWidgetRecord", table => table
                .ContentPartRecord()
            );

            ContentDefinitionManager.AlterTypeDefinition("VoiceCommandsWidget", cfg => cfg
                .WithPart("VoiceCommandsWidgetPart")
                .WithPart("WidgetPart")
                .WithPart("CommonPart")
                .WithSetting("Stereotype", "Widget")
            );

            return 1;
        }
    }
}